<?php 

/**
 * xml转换json
 * 
 * @author seyo
 *
 */
class xmltojson {
	
	public function get_xml($url)
	{
		$fileContents= file_get_contents($url);
		$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
		$fileContents = trim(str_replace('"', "'", $fileContents));
		return simplexml_load_string($fileContents);
	}

	public function parse($url, $ret_arr = 1)
	{
		$xml = $this->get_xml($url);
		$json = json_encode($xml);
		return  $ret_arr ? json_decode($json, 1) : $json;
	}

}